package com.example.mybatisplus.Pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private Integer StatusCode;//操作状态码
    private String message;//操作详情（状态码含义）
    private T data;//数据
    private Long count;//数据的行数

    public static <D> Result<D> success(ResultCode resultCode, D data, Long count) {
        return new Result<>(resultCode.getCode(), resultCode.getMessage(), data, count);
    }

    public static <D> Result<D> failure(ResultCode resultCode, D data, Long count) {
        return new Result<>(resultCode.getCode(), resultCode.getMessage(), data, count);
    }

    public static <D> Result<D> failure(ResultCode resultCode,String customMessage) {//customMessage自定义详情
        return new Result<>(resultCode.getCode(), customMessage, null, 0L);
    }

    public static <D> Result<D> failure(ResultCode resultCode) {
        return new Result<>(resultCode.getCode(), resultCode.getMessage(), null, 0L);
    }
}
